import { Column, CreateDateColumn, Entity, JoinColumn, ManyToOne, PrimaryColumn, UpdateDateColumn } from 'typeorm';
import { EntityHelper } from 'src/utils/entity-helper';
import { Exclude } from 'class-transformer';
import { Role } from 'src/role/entities/role.entity';

@Entity('user_admin')
export class AdminUser extends EntityHelper {
	@PrimaryColumn({
		name: 'id',
	})
	userId!: string;

	@Column()
	username!: string;

	@Column()
	nickname!: string;

	@Column({
		type: 'varchar',
		length: 200,
		select: false, // 普通查询时隐藏该字段
		comment: '密码',
	})
	@Exclude({ toPlainOnly: true })
	password!: string;

	@Column({ name: 'role_id' })
	roleId!: number;

	@Column({ default: 1, comment: '1 普通用户， 2：超管' })
	type!: number;

	@Column()
	@Column({ default: 1, comment: '用户状态: 1:正常， 0：冻结, -1: 永封' })
	status!: number;

	@Column()
	avatar?: string;

	@Column()
	notes?: string;

	@Column({ name: 'recent_login_time', type: 'varchar' })
	recentLoginTime?: Date;

	@Column({ type: 'varchar' })
	phone?: string;

	@Column({ type: 'varchar' })
	email?: string;

	@CreateDateColumn({ name: 'create_time' })
	createTime!: Date;

	@UpdateDateColumn({ name: 'update_time' })
	updateTime!: Date;

	@ManyToOne((type) => Role, (role) => role.id)
	@JoinColumn({ name: 'role_id' })
	role!: Role;
}
